<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Cache;

class Config extends Model
{
    protected $table = 'config';
    //缓存过期时间
    protected $cacheTime = 86400*7;

    /**
     * 根据key找到配置值
     * @param  [type] $key [description]
     * @return [type]      [description]
     */
   	public function cacheFindByKey($key){
   		$config = Cache::get(config('app.name').':config:'.$key);
   		if($config){
    		return $config;
    	}

    	$config = self::where('key',$key)->first();
    	if(!$config){
    		return false;
    	}
    	Cache::put(config('app.name').':config:'.$key, $config,$this->cacheTime);
    	return $config;
   	}

   	/**
   	 * key缓存清空
   	 * @return [type] [description]
   	 */
   	public function cacheEmpty($key){
   		Cache::forget(config('app.name').':config:'.$key);
   		return $this;
   	}
}
